<template>
  <div class="quantityConfig_content" v-spin-loading="isLoading">
    <div class="content_right">
      <div class="title">
        <div class="title_round"></div>
        <div>工程核量设置<span class="title_tip">（对先前已经发起的工程核量文件不受影响）</span></div>
      </div>
      <div class="switch_box">
        <div class="switch_row" v-for="item in configList" :key="item.sort">
          <div class="switch_row_left">
            <div>{{ item.label }}</div>
            <a-tag v-if="!!item.val" class="switch_tag">
              <template #icon>
                <icon-check-circle class="switch_icon" />
              </template>
              已启用
            </a-tag>
          </div>
          <a-switch v-model="item.val" :checked-value="1" :unchecked-value="0" @change="updateConfig(item)" />
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref } from "vue";
import { getQuantityConfig, updateQuantityConfig } from "@/apis/engineeringQuantity";

const isLoading = ref(false);
const configList = ref({});

const getConfigList = async () => {
  try {
    isLoading.value = true;
    const { data } = await getQuantityConfig();
    configList.value = data?.nuclearList ?? [];
    isLoading.value = false;
  } catch (e) {
    isLoading.value = false;
    console.log(e);
  }
};

const updateConfig = async item => {
  await updateQuantityConfig(item);
};

getConfigList();
</script>
<style lang="scss">
.quantityConfig_content {
  height: 100%;
  border-radius: 10px;
  position: relative;
  background: linear-gradient(180deg, #e3effe 0%, #f6f9ff 100%);
  .content_right {
    height: calc(100% - 40px);
    background: white;
    border-radius: 10px;
    padding: 20px;
    .title {
      display: flex;
      align-items: center;
      font-size: 18px;
      color: #131414;
      font-weight: 700;
      margin-bottom: 20px;
      .title_round {
        width: 6px;
        height: 6px;
        border-radius: 50%;
        background: #409eff;
        margin-right: 11px;
      }
      .title_tip {
        font-weight: 400;
        font-size: 14px;
        color: #86909c;
      }
    }
    .second_title {
      color: #1a1a1a;
      font-weight: 700;
      margin-bottom: 10px;
    }
    .switch_box {
      margin-bottom: 24px;
      .switch_row {
        display: flex;
        justify-content: space-between;
        padding: 8px 20px;
        align-items: center;
        background: #f5f7fa;
        border-radius: 4px;
        margin-bottom: 10px;
        .switch_row_left {
          display: flex;
          align-items: center;
          gap: 20px;
          .switch_tag {
            background-color: #e3f9e9;
            color: #14c85c;
          }
          .switch_icon {
            width: 14px;
            height: 14px;
            color: #14c85c;
            margin-right: 2px;
          }
        }
      }
    }
  }
}
</style>
